package com.base.controller;

import com.base.po.voip.Classify;
import com.base.service.ClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 商品分类管理服务端
 *
 * @author f
 */
@Controller
@RequestMapping("/admin")
public class index_Classify {

    @Autowired
    private ClassifyService classifyService; // 分类信息

    // 分类首页
    @RequestMapping("/classifyIndex")
    public ModelAndView classifyIndex(HttpServletRequest request) throws Exception {
        String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
        if (userid == null) return new ModelAndView("jsp/loginCheck"); // 未登录
        return new ModelAndView("jsp/index_Classify", "cList",
                classifyService.selectByAll(new Classify((byte) 1, userid)));
    }

    // 跳转添加分类
    @RequestMapping("/addClassify")
    public String addClassify() throws Exception {
        return "jsp/add_Classify";
    }

    // 跳转修改分类
    @RequestMapping("/updateClassify")
    public ModelAndView updateClassify(String id) throws Exception {
        return new ModelAndView("jsp/update_Classify", "classify", classifyService.selectByPrimaryKey(id));
    }
}
